package com.radar.common;

import ucar.ma2.DataType;
import ucar.nc2.*;

import java.util.List;

public enum ProductType {
    REF("Base Reflectivity", "dbz"),
    REFGRAY("Base Reflectivity gray", "dbz"),
    VEL("Base Velocity", "m/s"),
    SW("Spectral Width", ""),
    RF("", ""),
    ZDR("Differential Ref.", "dB"),
    PHI("Differential Phase", "deg"),
    RHO("Correlation Coe.", ""),
    TREF("Total Reflectivity", "dBZ"),
    KDP("Spec. Diff. Phase", "deg/km"),
    VILD("VIL Density", "g/m**3"),
    HCL("Hydrometeor Class", ""),
    OHP("One-Hour Precip.", "mm"),
    CR("Composite Ref.", "dBZ"),
    ET("Echo Tops", "km"),
    EB("Echo Bottoms", "km"),
    VIL("V Integrated Liquid", "kg/m**2"),
    CAPPI("Equal height plane position", ""),  //等高平面位置显示

    MAXREF("Maximum reflectivity" ,""),   //  最大反射率

    RCS(  "Reflectivity vertical profile" ,""), // 反射率垂直剖面

    VCS(  "Reflectivity vertical profile" ,"") ,    //速度垂直剖面
//    RZ(  "Rain intensity" ,""),  //雨强

    NHP(  "Hourly cumulative rainfall" ,""),   //  小时累积雨量

    RVD("Radial divergence" ,""),   //径向散度（RVD）
    ARD("Azimuth vorticity" ,""),   //方位涡度（ARD）
    CS("combined shear" ,""),  //合成切变（CS）
    VAD("Speed and azimuth display" ,""),  //速度方位显示（CS）
    LRA("Average value of layered composite reflectance" ,""),  //分层组合反射率平均值
    LRM("Maximum value of layered combination reflectivity" ,""),  //分层组合反射率最大值
    STI("Storm tracking" ,""),  //风暴追踪
    VWP("vertical wind profile" ,""),  //垂直风廓线

    ETB("Echo Tops", "km");  //ET EB

    //以下是一次产品  径向头 0 + 径向数据 0
//    R("Base Reflectivity" , "dBz"), // 基本反射率(R)
//    V("radial velocity" , "m/s") , // 径向速度(V)
//    W("Velocity spectrum width" , "m/s"), //速度谱宽(W)
//    UnR("Unfiltered basic reflectance" , "dBz");  //未滤波基本反射率(UnR)
//    VOL("Wow!" , ""); //体扫(VOL)

    //

    private String fullName;

    private String unit;

    public String getFullName() {
        return fullName;
    }

    public String getUnit() {
        return unit;
    }

    public Variable writeVariable(NetcdfFileWriter write, NetcdfFile netcdfFile, List<Dimension> dimensions){
        Variable variable = netcdfFile.findVariable(this.name());
        if(variable != null){
            return variable;
        }
        variable = write.addVariable(null, this.name(), DataType.BYTE, dimensions);
        variable.addAttribute(new Attribute("missing_value", (byte)-128));
        variable.addAttribute(new Attribute("add_offset", this == ProductType.VEL || this == ProductType.SW ? 62.5 : 32.5));
        variable.addAttribute(new Attribute("scale_factor", 2.0));
        variable.addAttribute(new Attribute("full_name",this.getFullName()));
        variable.addAttribute(new Attribute("units",this.getUnit()));
        return variable;
    }

    ProductType(String fullName, String unit) {
        this.fullName = fullName;
        this.unit = unit;
    }

    @Override
    public String toString() {
        return this.fullName + " (" + this.unit + ")";
    }
}
